//
//  U9AlertIInView.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/8/15.
//  Copyright © 2017年 UUU9. All rights reserved.
//

#import "U9AlertIInView.h"

@interface U9AlertIInView()

@property (nonatomic, strong) UILabel *label;

@end

static U9AlertIInView *alert;

@implementation U9AlertIInView

+ (instancetype)sharedAlertIInView{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        alert = [[U9AlertIInView alloc] init];
    });
    return alert;
}

- (instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor darkGrayColor];
        self.frame = CGRectMake(kScreenWidth * 0.5 - 50, kScreenHeight-250, 100, 40);
        self.layer.cornerRadius = 20;
        self.layer.masksToBounds = YES;
        self.hidden = YES;
        [self addSubViews];
    }
    return self;
}

- (void)addSubViews{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = UIColorFromRGB(kAllWhiteColor);
    _label = label;
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
}

- (void)setTitle:(NSString *)title{
    _title = title;
    _label.text = title;
}

- (void)showAlert:(AlertBlock)block{
    [UIView animateWithDuration:0.5 animations:^{
        self.hidden = NO;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self dissmissAlert:block];
        });
    }];
}

- (void)dissmissAlert:(AlertBlock)block{
    [UIView animateWithDuration:0.5 animations:^{
        block();
        self.hidden = YES;
    }];
}





@end
